package org.wzl.springapplication.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.wzl.springapplication.mapper.TaskRecordMapper;
import org.wzl.springapplication.pojo.TaskRecord;
import org.wzl.springapplication.service.TaskRecordService;
import org.wzl.springapplication.utils.Result;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/task_record")
public class TaskRecordController {

    @Autowired
    private TaskRecordService taskRecordService;

    @Autowired
    private TaskRecordMapper taskRecordMapper;

    @PostMapping("/insert")
    public Result insert(@RequestBody TaskRecord taskRecord) {
        taskRecord.setCreateDate(new Date());
        taskRecordService.getBaseMapper().insert(taskRecord);
        return Result.add_("msg" , "ok");
    }

    @GetMapping("/getByName")
    public Result getByName(String name) {
        List<TaskRecord> list = taskRecordService.getByName(name);
        return Result.add_("list" , list);
    }

    @GetMapping("/getAllName")
    public Result getAllName() {
        return Result.add_("list" , taskRecordMapper.getAllName());
    }

    @GetMapping("/getAllRecordByNameInWeek")
    public Result getAllRecordByNameInWeek(String name) {
        return Result.add_("list" , taskRecordMapper.getAllRecordByNameInWeek(name));
    }

    @GetMapping("/getCountByName")
    public Result getCountByName(String name) {
        return Result.add_("list" , taskRecordMapper.getCountByName(name));
    }

}
